package com.example.demo.handler;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import cn.dsna.util.images.ValidateCode;

@Api("生成验证码")
@RestController
@RequestMapping("/picCode")
public class PicCodeController {
	
	@ApiOperation(value="生成验证码",notes="得到验证码")
	@RequestMapping(value="/getCode" ,method=RequestMethod.GET)
	public void getCoide(HttpServletRequest request,HttpServletResponse response){
		ValidateCode code=new ValidateCode(100, 30, 4, 30);
		//获取登录验证码
		String codeVal=code.getCode();
		//将验证码存到Session
		request.getSession().setAttribute("loginCode"+request.getSession().getId(), codeVal);
		//将图形化验证码响应到页面
		try {
			code.write(response.getOutputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

